<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配送关系管理</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>选择配送企业</h1>
        <ol class="breadcrumb">
           <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">目录管理</a></li>
            <li class="active"><a href="#">配送关系管理</a></li>
            <li class="active"><a href="#">设置配送关系</a></li>
        </ol>
    </section>
    
		
		<section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">  
                <div class="form-group form-group-xs">
			            <label>企业编码：</label>
			            <input class="form-control" type="text" id="delCompCode" name="delCompCode" placeholder="企业编码"  />
			        </div>              
				    <div class="form-group form-group-xs">
			            <label>企业名称：</label>
			            <input class="form-control" type="text" id="delCompName" name="delCompName" placeholder="企业名称"  />
			        </div>
	                <button type="button" onclick="gridSerch();" class="btn btn-success btn-sm">查&nbsp;询</button>
	            </div>
			</div>
		</div>
<div style="margin-top: 5px;"></div>
	<table class="jqgrid" id="list4"></table>
<div style="margin-top: 10px;"></div>
<div id="prowed2"></div>


<div class=" box box-warning bottongroup" id="bottongroup">
			<label  onclick="window.location.href='${ctx}/baseDel/toDelByHospList.html?compCode=${param.compCode}'"   class="btn btn-default btn-sm" >返 回</label>
		</div>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">
function setDel(){
		  $("#buttonID").attr("disabled",true);
		  setTimeout( function fun(){
				$("#buttonID").attr("disabled",false);
			 },2000);
		  var rowIds = $("#list4").jqGrid("getGridParam", "selarrrow") || [];
			if (rowIds.length <= 0) {
				$.HN.message.alert("请选择配送企业！", "消息", "error");
				return;
			}

			$.HN.message.confirm("确定设置吗？", '', '').on(function (e) {
	            if (e) {

			var compCode = '${param.compCode}';
			var hospCode = '${param.hospCode}';
			var list = [];
			for (var i=0; i<rowIds.length; i++) {
				rowId = rowIds[i];
				var rowdata = $("#list4").jqGrid('getRowData', rowId);
				list.push({
		    		"delCompCode":rowdata.comp_code});
			}
			
			$.post("${pageContext.request.contextPath}/baseDel/setDelByHospWithDelcomp.html", {
				"array" : json.jsonToString(list),"hospCode":hospCode,"compCode":compCode
				}, function(result) {
					if (result.success) {
						$.HN.message.alert("设置成功！", "消息", "success");
						window.location.href='${ctx}/baseDel/toDelByHospList.html?compCode=${param.compCode}';
					} else {
						$.HN.message.alert(result.msg, "消息", "error");
					}


				}, "json");
	            }
			});
   
}

function setOneDel(delCompCode){
	  $.HN.message.confirm("确定设置吗？", '', '').on(function (e) {
          if (e) {
		var compCode = '${param.compCode}';
		var hospCode = '${param.hospCode}';
		var list = [];
		list.push({"delCompCode":delCompCode});
		$.post("${pageContext.request.contextPath}/baseDel/setDelByHospWithDelcomp.html", {
			"array" : json.jsonToString(list),"hospCode":hospCode,"compCode":compCode
			}, function(result) {
				if (result.success) {
					$.HN.message.alert("设置成功！", "消息", "success");
					window.location.href='${ctx}/baseDel/toDelByHospList.html?compCode=${param.compCode}';
				} else {
					$.HN.message.alert(result.msg, "消息", "error");
				}


			}, "json");
          }
		});

}
$(document).ready(function (){
	jQuery("#list4").jqGrid({
		url: "${ctx}/baseDel/getSetDelByHospWithDelcompData.html?hospCode=${param.hospCode}&compCode=${param.compCode}",
	    mtype: "POST",
		datatype: "json",
		autowidth: true,
		shrinkToFit: true,
		height: 270,
	   	colNames:['操作','企业编码','企业名称','组织机构代码','联系人','联系电话','已设数量'],
	   	colModel:[
			{name:'oper',index:'comp_code',width:40,align:"center", sorttype:false,sortable:false,
	   			formatter:function(val, opts,row) {
		   			 return "<a href=\"javascript:void(0);\" onclick=\"setOneDel('" + row.comp_code + "')\">设置</a>"
		   			}},
	   		{name:'comp_code',index:'comp_code',key:true,width:100,align:"center", sorttype:false,sortable:false},
	   		{name:'comp_name',index:'comp_name',width:150,align:"center",sortable:false,sortable:false,
	   			formatter:function(val, opts,row) {
		   			 return "<a href=\"javascript:void(0);\" onclick=\"showCompInfo('"+row.comp_code+"', '"+ val +"')\">"+val+"</a>"
		   			}},
	   		{name:'org_code',index:'org_code',width:80, align:"center",sorttype:false,sortable:false},
	   		{name:'contact_name',index:'contact_name',width:80, align:"center",sorttype:false,sortable:false},
	   		{name:'contact_telephone',index:'contact_telephone',width:60,align:"center", sorttype:false,sortable:false},
	   		{name:'hospCount',index:'hospCount',width:80, align:"center",sorttype:false,sortable:false,formatter:function(val,option,rowdata){

	   			var str = "<a href='${ctx}/baseGoods/toDelRelationHospList.html?delCompCode="+rowdata.comp_code+"&compName="+rowdata.comp_name+"&prodCompCode=${param.compCode}'>"+val+"</a>";
		   			return str;
	   		}},
	   	],
		gridComplete: function(){
			
		},
		 rowNum: 20,
	     rowList: [10, 20, 50,100],
	     rownumbers: true,
	     multiselect: false,
	     pager: "#prowed2",
	     viewrecords: true,
	     caption: "${compName}——${hospName}",
	     jsonReader: {
	         repeatitems: false,
	         id: "ids"
	     }
	   	
	});
})

function gridSerch(){
	var delCompCode = $.trim($("#delCompCode").val());
	var delCompName = $.trim($("#delCompName").val());
	$("#list4").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"delCompCode":delCompCode,
        		"delCompName":delCompName,
        		"hospCode":"${param.hospCode}"},
        		page:1
    }).trigger("reloadGrid"); //重新载入  
}

function gridAreaSerch(){
	var areaCode = $.trim($("#areaCode").val());
	var areaName = $.trim($("#areaName").val());
	$("#list5").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"areaCode":areaCode,
        		"areaName":areaName}
    }).trigger("reloadGrid"); //重新载入  
}
	    
</script>
</body>
</html>